const modle = require('../../modle/shopper')
const shopperusermodle = require('../../modle/shopperuser')
const { Op } = require("sequelize")
module.exports = {
    async addshopper(data) {
        await shopperusermodle.update({ kai: 1 }, {
            where: {
                id: data.userid
            }
        })
        return await modle.create({ ...data })
    },
    async findshop(userid) {
        return await modle.findAll({
            where: {
                userid
            }
        })
    },
    async getuserdata(limit, offset, findkey) {
        const { namekey, valuexb } = findkey
        if (valuexb == 0) {
            return await shopperusermodle.findAndCountAll({
                where: {
                    name: {
                        [Op.like]: `%${namekey}%`
                    }
                },
                limit,
                offset: (offset - 1) * limit,
            })
        } else if (valuexb == 2) {
            return await shopperusermodle.findAndCountAll({
                where: {
                    name: {
                        [Op.like]: `%${namekey}%`
                    },
                    kai: {
                        [Op.or]: [0, 2]
                    }
                },
                limit,
                offset: (offset - 1) * limit,
            })
        }
        return await shopperusermodle.findAndCountAll({
            where: {
                name: {
                    [Op.like]: `%${namekey}%`
                },
                kai: 3
            },
            limit,
            offset: (offset - 1) * limit,
        })

    },
    async deleteid(id) {
        return await shopperusermodle.destroy({
            where: {
                id
            }
        })
    }, async updetebox(id, data) {
        return await shopperusermodle.update({ ...data }, {
            where: {
                id
            }
        })
    }
}